<template>



<el-form :model="loginForm" :rules="rules" ref="loginForm" label-width="100px" class="demo-ruleForm">
  <el-form-item label="用户名" prop="username">
    <el-input v-model="loginForm.username"></el-input>
  </el-form-item>

    <el-form-item label="活动名称" prop="password">
    <el-input v-model="loginForm.password"></el-input>
  </el-form-item>


  <el-form-item>
    <el-button type="primary" @click="startLogin">登录</el-button>
    <el-button @click="resetLogin">重置</el-button>
  </el-form-item>
</el-form>





</template>




<script>


  import axios from 'axios'


  export default {
    data() {
      return {
          loginForm: {
          username: 'admin',
          password:'123456'
        },
        rules: {
          username: [
            { required: true, message: '请输入用户名', trigger: 'blur' },
            { min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' }
          ],
          password: [
            { required: true, message: '请输入密码', trigger: 'blur' },
            { min: 3, max: 8, message: '长度在 3 到 8 个字符', trigger: 'blur' }
          ]

        }
      };
    },
    methods: {
      startLogin() {
        this.$refs.loginForm.validate((valid) => {
          if (!valid) {
          return console.log('校验失败')

          }
          axios.post('http://localhost:8888/api/private/v1/login',this.loginForm)
          .then(res =>{
            console.log("111");

            if (res.data.meta.status === 200) {
            //   this.$message({
            //     message:res.data.meta.msg,
            //     type:'success',
            //     duration:800
            //   })
            //   this.$router.push('/home')
            // }else{
            //   this.$message({
            //     message:res.data.meta.msg,
            //     type:'error',
            //     duration:800
            //   })
            }
          })
        });
      },

     resetLogin() {
        this.$refs.loginForm.resetFields();
      }
    }
  }
</script>
